package cn.yunhe.service;

import cn.yunhe.dao.INewsDao;
import cn.yunhe.entity.News;
import cn.yunhe.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("newsService")
public class NewsService {

    @Autowired
    @Qualifier("newsDao")
    private INewsDao newsDao;

    public Map<String,Object> getAllNews(int pageIndex){
        Map<String,Object> map = new HashMap<String, Object>();
        int totalRows = newsDao.getTotalRows();
        int totalPage = PageUtil.getTotalPage(totalRows);
        List<News> newsList = newsDao.getAllNews(pageIndex);
        map.put("totalPage",totalPage);
        map.put("newsList",newsList);
        return map;
    }
}
